package com.it.shiro.sys.controller;

import com.it.base.resposne.JsonData;
import com.it.shiro.sys.entity.User;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @program: learning
 * @description: 登陆控制曾
 * @author: Lefnmg
 * @create: 2018-11-07 22:13
 **/
@RestController
@RequestMapping("/sys")
public class LoginController {
    /**
     * shiro 登录接口
     *
     * @param user
     * @return
     */
    @RequestMapping("/login")
    public JsonData login(User user) {
        Subject subject = SecurityUtils.getSubject();
        long timeout = subject.getSession().getTimeout();
        System.out.println(timeout);
        UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword());
        subject.login(token);
        return JsonData.ok().put("token",subject.getSession().getId()).put("msg","登陆成功");
    }

}
